(********************************************************************)
(*	file: 		ADSPInstall.p										*)
(*	version:	.5alpha												*)
(* 																	*)
(* Open the ".DSP" driver and establish memory for the ADSPBlock.	*)
(* Creates the connection listener for this node.					*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	29-Jan-88												*)
(* 			©	Copyright 1988, Apple Computer, Inc.				*)
(*			All Rights Reserved										*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	   	| By	|	 				Description				*)
(* ----------------------------------------------------------------	*)
(* 29-Jan-88	| DK	| file created								*)
(* 17-Mar-88	| DK	| ALPHA RELEASE								*)
(* ----------------------------------------------------------------	*)
(********************************************************************)

(********************************************************************
							Build Sequence

pascal -o "{hpo}"adspInstall.p.o "{adsp}"adspInstall.p
link -m ENTRYPOINT  -rt XCMD=1300 -sn Main=ADSPInstall¶
	"{hpo}"adspInstall.p.o¶
	"{libraries}"Interface.o ¶
	"{plibraries}"paslib.o¶
	-o "{hp}"HyperADSPTest
		 
********************************************************************)

{$R-}
{$S ADSPInstall}
UNIT Koscheka;

(*******************************************************************)
INTERFACE
(*******************************************************************)

Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );

(*******************************************************************)
IMPLEMENTATION
(*******************************************************************)

PROCEDURE ADSPInstall( paramPtr: XCmdPtr ); FORWARD;


Procedure EntryPoint( paramPtr : XCmdPtr );
	Begin
		ADSPInstall( paramPtr );
	End;
	
Procedure ADSPInstall( paramPtr : XCmdPtr );
VAR
	refnum			: integer;
	adsp			: ADSPPtr;
	error			: OSErr;
	mppPB			: MPPParamBlock;
	
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }	

BEGIN
	adsp 	:= ADSPPtr(RetrieveHandle( GLOBALDSPDATA ));
	error	:= noErr;
	
	IF adsp = NIL THEN
		BEGIN
			error := MPPOpen;
			
			IF error = noErr THEN
				BEGIN
					mppPB.newSelfFlag := 1;
					error := PSetSelfSend( @mppPB, SYNC );
					{*** Don't care if selfsend works ***}
					
					error := OpenDriver( '.DSP', refnum );
				END;

			IF error = noErr THEN { if global block not allocated }
				BEGIN		{ and set up the connection listener..}

					adsp := ADSPPtr( NewPtr( sizeOf( ADSPBLOCK ) ));
					
					IF adsp <> NIL THEN
						WITH adsp^ DO
							BEGIN
								addr.aNode 	:= 0;
								addr.aNet 	:= 0;
								addr.aSocket:= 0;
								ends 		:= NIL;
								dspRefNum 	:= refnum;
								oldSelf		:= mppPB.oldSelfFlag;
								ccbRef		:= 0;
								checkPoint	:= CLOSE_OK;
								
								WITH pb DO
									BEGIN
										{ OKAY to open a listening socket }
										ioCRefNum 	:= refnum;
										csCode 		:= dspCLInit;
										ioCompletion:= NIL;
										ccbPtr		:= @adsp^.ccb;
										localSocket	:= 0;
										error 		:= PBControl( @adsp^.pb, SYNC );
	
										IF error = noErr THEN
										BEGIN
										{ Listener is now all ears	}
										 	ccbRef				:= ccbRefNum;
											addr.aSocket 		:= localSocket;
											csCode				:= dspCLListen;
											filterAddress.aNet 	:= 0;
											filterAddress.aNode	:= 0;
											filterAddress.aSocket:= 0;
											error := PBControl( @adsp^.pb, ASYNC );
										END;
									END;
							END;		{*** with adsp 	***}
							
					IF error = noErr THEN
						BEGIN
							SaveHandle( GLOBALDSPDATA, LongInt( adsp ) );
							SaveHandle( GLOBALSKTDATA, LongInt( adsp^.addr ) );
						END;
			
				END
		END;
		
		paramPtr^.returnValue := ErrorReturn( error );
END;

end.
